
// 是否实时推送状态
export const isRealTime = data => {
  const { autoRefresh, dataSourceType } = data || {};
  if (['xMinerRedisRealTime', 'kafka'].includes(dataSourceType)) {
    return true;
  }
  if (!autoRefresh) {
    return false;
  }
  if (dataSourceType !== 'xMiner') {
    return getNoXminerRealTime(data);
  }
  const { switchEnable, actType } = autoRefresh;
  if (!switchEnable) {
    return false;
  }
  return actType === 'push';
};

const getNoXminerRealTime = data => {
  const { dataSourceType, dataVal } = data || {};
  if (dataSourceType !== 'xVueApi') {
    return false;
  }
  const isPreview = window.xVueWeb.app.config.globalProperties.$xvueIsRunAsUserModel;
  const reg = /^{{(.*?)\..*?}}$/;
  const result = dataVal.match(reg);
  let refName = '';
  if (result && result[1]) {
    [, refName] = result;
  }
  let xVueApiConfig = {};
  if (refName === 'Global'.toLowerCase()) { // 需要这样写，不然跟vite配置冲突
    xVueApiConfig = window._adoPremise;
  } else {
    xVueApiConfig = window.xVueWeb.app.config.globalProperties?.xvGlobalRfs?.[refName];
  }

  // xvueapi配置的是redis数据源的时候,在编排面按照实时数据逻辑渲染组件,预览面的时候按照非实时的逻辑渲染组件
  if (!isPreview && xVueApiConfig?.apiConfig?.dataSourceType === 'xMinerRedisRealTime') {
    return true;
  }
  return false;
};
